package io.dy.controller;

import io.dy.model.AccountModel;
import io.dy.service.AccountService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author dmj
 * @date 2023年10月12日 下午9:55
 */
@RestController
@RequestMapping("/dy/account")
@RequiredArgsConstructor
public class AccountController {

    private final AccountService accountService;

    @GetMapping
    public List<AccountModel> searchAllAccount(){
        return accountService.list();
    }


    @GetMapping("/{accountId}/{balance}")
    public Boolean deductionBalance(@PathVariable("accountId") Long accountId, @PathVariable("balance") BigDecimal balance){
        return accountService.deductionBalance(accountId, balance);
    }

    @GetMapping("/{id}")
    public Boolean selectLeftAmtById(@PathVariable("id") Long id){
        return accountService.selectLeftAmtById(id);
    }
}
